<?php

require_once("lib/exception/internal_error_exception.php");
require_once("lib/exception/model_exception.php");
require_once("lib/exception/parameters_exception.php");

require_once("model/autorfacade/delegate/autor_facade_delegate.php");

require_once('model/autorfacade/plain/actions/register_autor_action.php');
require_once('model/autorfacade/plain/actions/login_action.php');
require_once('model/autorfacade/plain/actions/change_password_action.php');
require_once('model/autorfacade/plain/actions/get_user_info_action.php');
require_once('model/autorfacade/plain/actions/update_user_action.php');
require_once('model/autorfacade/plain/actions/get_statics_user_action.php');
require_once('model/autorfacade/plain/actions/send_message_action.php');
require_once('model/autorfacade/plain/actions/get_all_mail_inbox_action.php');
require_once('model/autorfacade/plain/actions/get_all_mail_send_action.php');
require_once('model/autorfacade/plain/actions/get_message_accion.php');
require_once('model/autorfacade/plain/actions/change_message_to_new_action.php');
require_once('model/autorfacade/plain/actions/change_message_to_old_action.php');
require_once('model/autorfacade/plain/actions/delete_message_action.php');

class Plain_autor_facade_delegate extends Autor_facade_delegate {

	//registra un usuario en la aplicacion
	public function register_autor($autor_to) {
		try {
			$action = new Register_autor_action($autor_to);
			return $action->do_execute();
		}
		catch (Internal_error_exception $e) {
			throw $e;
		}
		catch (Parameters_exception $e) {
			throw $e;
		}
		catch (Model_exception $e) {
			throw $e;
		}
		catch (Exception $e) {
			throw new Exception("Internal error exception --> " . $e);
		}	
	}
	
	//loguear un usuario en la aplicacion
	public function login($login, $password, $is_encrypted) {
		try {
			$action = new Login_action($login, $password, $is_encrypted);
			return $action->do_execute();
		}
		catch (Internal_error_exception $e) {
			throw $e;
		}
		catch (Model_exception $e) {
			throw $e;
		}
		catch (Parameters_exception $e) {
			throw $e;
		}
		catch (Exception $e) {
			throw new Exception("Internal error exception --> " . $e);
		}	
	}
	
	//cambia el password de un usuario en la aplicacion
	public function change_password($login, $old_password, $new_password) {
		try {
			$action = new Change_password_action($login, $old_password, $new_password);
			return $action->do_execute();
		}
		catch (Internal_error_exception $e) {
			throw $e;
		}
		catch (Model_exception $e) {
			throw $e;
		}
		catch (Parameters_exception $e) {
			throw $e;
		}
		catch (Exception $e) {
			throw new Exception("Internal error exception --> " . $e);
		}	
	}
	
	//Obtiene todos los datos de un usario
	public function get_user_info($login) {
		try {
			$action = new Get_user_info_action($login);
			return $action->do_execute();
		}
		catch (Internal_error_exception $e) {
			throw $e;
		}
		catch (Model_exception $e) {
			throw $e;
		}
		catch (Exception $e) {
			throw new Exception("Internal error exception --> " . $e);
		}	
	}
	
	//cambia los datos de un usuario en la aplicacion
	public function update_user($autor_to) {
		try {
			$action = new Update_user_action($autor_to);
			return $action->do_execute();
		}
		catch (Internal_error_exception $e) {
			throw $e;
		}
		catch (Model_exception $e) {
			throw $e;
		}
		catch (Exception $e) {
			throw new Exception("Internal error exception --> " . $e);
		}	
	}
	
	//obtiene las estadisticas de un usuario
	public function get_statics_user($login) {
		try {
			$action = new Get_statics_user_action($login);
			return $action->do_execute();
		}
		catch (Internal_error_exception $e) {
			throw $e;
		}
		catch (Model_exception $e) {
			throw $e;
		}
		catch (Exception $e) {
			throw new Exception("Internal error exception --> " . $e);
		}	
	}
	
	//envia un sms a un usuario
	public function send_message($message) {
		try {
			$action = new Send_message_action($message);
			return $action->do_execute();
		}
		catch (Internal_error_exception $e) {
			throw $e;
		}
		catch (Model_exception $e) {
			throw $e;
		}
		catch (Parameters_exception $e) {
			throw $e;
		}
		catch (Exception $e) {
			throw new Exception("Internal error exception --> " . $e);
		}	
	}
	
	//visualiza la bandeja de entrada de un usuario
	public function get_all_mail_inbox($login, $start_index, $count) {
		try {
			$action = new get_all_mail_inbox_action($login, $start_index, $count);
			return $action->do_execute();
		}
		catch (Internal_error_exception $e) {
			throw $e;
		}
		catch (Model_exception $e) {
			throw $e;
		}
		catch (Exception $e) {
			throw new Exception("Internal error exception --> " . $e);
		}	
	}
	
	//visualiza la bandeja de salida de un usuario
	public function get_all_mail_send($login, $start_index, $count) {
		try {
			$action = new get_all_mail_send_action($login, $start_index, $count);
			return $action->do_execute();
		}
		catch (Internal_error_exception $e) {
			throw $e;
		}
		catch (Model_exception $e) {
			throw $e;
		}
		catch (Exception $e) {
			throw new Exception("Internal error exception --> " . $e);
		}	
	}
	
	//visualiza el contenido completo de un sms
	public function get_message($number_message) {
		try {
			$action = new Get_message_accion($number_message);
			return $action->do_execute();
		}
		catch (Internal_error_exception $e) {
			throw $e;
		}
		catch (Model_exception $e) {
			throw $e;
		}
		catch (Exception $e) {
			throw new Exception("Internal error exception --> " . $e);
		}	
	}
	
	//Cambia el estado de un mensaje a leido
	public function change_message_to_new($number_message) {
		try {
			$action = new Change_message_to_new_action($number_message);
			return $action->do_execute();
		}
		catch (Internal_error_exception $e) {
			throw $e;
		}
		catch (Model_exception $e) {
			throw $e;
		}
		catch (Exception $e) {
			throw new Exception("Internal error exception --> " . $e);
		}	
	}
	
	//Cambia el estado de un mensaje a no leido
	public function change_message_to_old($number_message) {
		try {
			$action = new Change_message_to_old_action($number_message);
			return $action->do_execute();
		}
		catch (Internal_error_exception $e) {
			throw $e;
		}
		catch (Model_exception $e) {
			throw $e;
		}
		catch (Exception $e) {
			throw new Exception("Internal error exception --> " . $e);
		}	
	}
	
	//borra un mensaje
	public function delete_message($number_message) {
		try {
			$action = new Delete_message_action($number_message);
			return $action->do_execute();
		}
		catch (Internal_error_exception $e) {
			throw $e;
		}
		catch (Model_exception $e) {
			throw $e;
		}
		catch (Exception $e) {
			throw new Exception("Internal error exception --> " . $e);
		}	
	}
}
?>